-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify Python binding of StorageConfig
#371
Simplify Python binding of StorageConfig
#371
Conversation
impl From<PyS3Credentials> for StaticS3Credentials { | ||
fn from(credentials: PyS3Credentials) -> Self { | ||
StaticS3Credentials { | ||
access_key_id: credentials.access_key_id, | ||
secret_access_key: credentials.secret_access_key, | ||
session_token: credentials.session_token, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's useful to have a value-to-value From
impl instead of just an impl on &PyS3Credentials
so that you can avoid the clones when not needed.
} | ||
|
||
#[classmethod] | ||
#[pyo3(signature = ( | ||
bucket, | ||
prefix, | ||
endpoint_url = None, | ||
allow_http = None, | ||
allow_http = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow_http
can only be a bool, so why not default to false
instead of defaulting to None
and then unwrapping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason, just moving fast
allow_http: bool | None | ||
region: str | None | ||
|
||
def __init__(self, storage: Memory | Filesystem | S3): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no #[new]
method defined on StorageConfig
, so it wasn't possible to directly construct this anyways.
impl AsRef<StorageConfig> for PyStorageConfig { | ||
fn as_ref(&self) -> &StorageConfig { | ||
&self.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This AsRef
impl means that if you have a PyStorageConfig
and you want to access an &StorageConfig
, you can just call .as_ref()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks for cleaning this up
I'm starting to read through the storage binding for #266.
As it stands, you recreate the content of the struct in the Python binding as well, and then you convert the content of the struct in the Python bindings to the content of the struct in the Rust code.
In my opinion it's best to have as little logic as possible in the binding code and make it a slim wrapper around the underlying core Rust code. Minimizing the logic in the bindings also makes it simpler to make bindings to other languages in the future (#356)